﻿using ETA.Entity;
using ETA.DomainEnum;
using FluentNHibernate.Mapping;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ETA.EntityMappings
{
    public class UserMap : ClassMap<User>
    {
        public UserMap()
        {
            Id(x => x.UserId);
            Map(x => x.UserName);
            Map(x => x.Age);
            Map(x => x.Ahousehold);
            Map(x => x.Birthday);
            Map(x => x.CreateDate);
            Map(x => x.EducationLevelEnum).CustomType<EducationLevelEnum>().Column("EducationLevel");
            Map(x => x.SexEnum).CustomType<SexEnum>().Column("Sex");
            //TODO 此处添加上 性别枚举 报SqlParameterCollection 的 Count=19 的索引 19 无效。 错 后期修改 2014-6-16 17:22:53  
            //2014-06-16 21:31:30 已解决 由于下方同时管理了sex字段所以会导致此错误 实际 如果管理了枚举就无须再管理 字段了
            Map(x => x.Email);
            Map(x => x.EmailActive);
            Map(x => x.IDCard);
            Map(x => x.IsDelete);
            Map(x => x.LoginName);
            Map(x => x.Mobile);
            Map(x => x.MobileActive);
            Map(x => x.ModifyDate);
            Map(x => x.Password);
            Map(x => x.QQ);
            //Map(x => x.Sex);
            Map(x => x.WeiXin);
            Map(x => x.NewJobs);
            Map(x => x.OrginalJobs);
            Map(x => x.Height);
            Map(x => x.Weight);
            Map(x => x.EyeGlass);
            Map(x => x.EyeLeft);
            Map(x => x.EyeRight);
            Map(x => x.HasAbroadExperience);
            Map(x => x.IsGotpassport);
            Map(x => x.IsMarried);
            Map(x => x.Note);
            Map(x => x.FlowChangeTime);
            Map(x => x.IsReferrer).Not.LazyLoad();
            References(x => x.CurrentStep).Column("FlowStepId");
            HasManyToMany<Roler>(x => x.Rolers)
                .Table("RolerRealtion")
                .ChildKeyColumn("RolerId")
                .ParentKeyColumn("UserId");
            //2014-06-14 22:21:53 此处无须关联  流程 单独根据 用户id获取
            HasMany<RegistrationMainForm>(x => x.RegistrationMainForms).KeyColumn("UserId").Where(t => t.IsDelete == false).Not.LazyLoad();
            References(x => x.RegistrationBind).Column("RegistrationBindId")
           .Cascade.All();
        }
    }
}
